﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MedicalManagementAPP.Utils
{
    static class MedicineManager
    {
        static public string[][] GetMedicineTypes()
        {
            string sql;
            string[][] result = new string[2][];
            DataTable data;
            // 处方药
            sql = "select MType from Medicines where Prescription = 'True'";
            data = Connection.SqlQuery(sql);
            string[] arr1 = new string[data.Rows.Count];
            for (int i = 0; i < data.Rows.Count; i++)
            {
                arr1[i] = data.Rows[i][0].ToString();
            }
            result[0] = arr1;

            // 非处方药
            sql = "select MType from Medicines where Prescription = 'False'";
            data = Connection.SqlQuery(sql);
            string[] arr2 = new string[data.Rows.Count];
            for (int i = 0; i < data.Rows.Count; i++)
            {
                arr2[i] = data.Rows[i][0].ToString();
            }
            result[1] = arr2;

            return result;
        }
        /// <summary>
        /// 返回MedicineID,Stock,Price,Mtype,MName,MUnit from Medicines
        /// </summary>
        /// <param name="Mtype">种类名称</param>
        /// <returns>MedicineID,Stock,Price,Mtype,MName,MUnit from Medicines</returns>
        static public DataTable GetMedicineByType(string Mtype)
        {
            string sql = "select MedicineID,Stock,Price,Mtype,MName,MUnit from Medicines where MType=@Mtype";
            SqlParameter[] parameters = new SqlParameter[]
            {
                new SqlParameter("@Mtype",Mtype)
            };
            return Connection.SqlQuery(sql, parameters);
        }

    }
}
